﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Microsoft.Xaml.Behaviors;
using SimpleTool.ActivityUnit;

namespace SimpleTool.Server
{
    class Behavior : Behavior<UIElement>
    {
        public ICommand CmdLeftKeyClick
        {
            set
            {
                SetValue(LeftKeyClickProperty, value);
            }
            get
            {
                return (ICommand)GetValue(LeftKeyClickProperty);
            }
        }

        public static readonly DependencyProperty LeftKeyClickProperty = DependencyProperty.Register
        (
            nameof(CmdLeftKeyClick),
            typeof(ICommand),
            typeof(Behavior),
            new PropertyMetadata(null)
        );

        protected override void OnAttached()
        {
            AssociatedObject.MouseLeftButtonDown += MouseButtonEvent;
            base.OnAttached();
        }

        protected override void OnDetaching()
        {
            AssociatedObject.MouseLeftButtonDown -= MouseButtonEvent;
            base.OnDetaching();
        }

        private void  MouseButtonEvent(object sender, MouseButtonEventArgs e)
        {
            CmdLeftKeyClick.Execute(null);
        }
    }
}
